# coding=utf-8

FILE ='''
#include "func%s.h"

void f%s(float val)
{
	cout << sqrt(val) << endl;
}
'''

HEAD ='''
#include <iostream>
#include <cstdlib>
#include <new>
#include <memory>
#include <climits>
#include <utility>
#include <ctime>
#include <windows.h>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <array>
#include <forward_list>
#include <random>
#include <ratio>
#include <cfenv>
#include <codecvt>
#include <atomic>

using namespace std;

void f%s(float val);
'''

N=20

def fn_gen():
	for i in range(1, N+1):
		with open("func%s.h" % i, "w") as f:
			f.write(HEAD % i)
		with open("func%s.cpp" % i, "w") as f:
			f.write(FILE % (i, i))

def call_fn():
	with open("func_call.cpp", "w") as f:
		for i in range(1, N+1):
			f.write("f%s(%s);\n" % (i, i))
			
			
def fmt_str(n, str, join_str = '\n'):
	s = []
	for i in range(1, n+1):
		s.append(str.format(N=i))
	return '\n'.join(s)

def inc_str():
	return fmt_str(N, '#include "func{N}.h"')

def call_str():
	return fmt_str(N, 'f{N}({N});')

def prog_str():
	with open("main.cpp.txt") as f:
		s = f.read()
	s = s.format(INCLUDE=inc_str(), CALL=call_str(), LP="{", RP="}")
	with open("main.cpp", "w") as f:
		f.write(s)

		
def depend_fn():
	with open("depend_fn.cpp", "w") as f:
		for i in range(1, N+1):
			f.write("func%s.cpp " % i)
		
def declare_fn():
	with open("declare_fn.cpp", "w") as f:
		for i in range(1, N+1):
			f.write("void f%s(float val);\n" % i)

			# f.write(FILE % i)
	# for i in range(1, N+1):
		# with open("func%s.cpp" % i, "w") as f:
			# f.write(FILE % i)

def depend_str():
	return fmt_str(N, 'func{N}.cpp ')
			
def cmake_str():
	with open("CMakeLists.txt.txt") as f:
		s = f.read()
	s = s.format(FUNCS=depend_str(), LP="{", RP="}")
	with open("CMakeLists.txt", "w") as f:
		f.write(s)
		
if __name__ == "__main__":
	fn_gen()
	# call_fn()
	# depend_fn()
	# declare_fn()
	prog_str()
	cmake_str()